package com.hy.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.hy.config.IntentRecognitionConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Service
public class DynamicDataService {

    @Autowired
    private IntentRecognitionConfig intentRecognitionConfig;

    // 缓存解析后的数据
    private final Map<String, String> industryDataCache = new ConcurrentHashMap<>();
    private final Map<String, String> detailDataCache = new ConcurrentHashMap<>();

    public String getIndustryData() {
        return industryDataCache.computeIfAbsent("industry_data", k -> {
            return intentRecognitionConfig.getIndustryData().replaceAll("\\s+", ""); // 去除空格
        });
    }

//    public Map<String, String> getDetailData() {
//        return detailDataCache.computeIfAbsent("detail_data", k -> {
//            try {
//                return new ObjectMapper().readValue(intentRecognitionConfig.getDetailData(), HashMap.class);
//            } catch (Exception e) {
//                // 记录异常日志
//                System.err.println("解析明细数据时出错: " + e.getMessage());
//                // 返回空的 HashMap
//                return new HashMap<>();
//            }
//        });
//    }
}
